//
//  PacketQueue.h
//  ffplay
//
//  Created by 熊友良 on 2019/8/21.
//  Copyright © 2019 熊友良. All rights reserved.
//

#ifndef PacketQueue_h
#define PacketQueue_h

#include <stdio.h>
#include <libavcodec/avcodec.h>
#include <SDL.h>

extern AVPacket flush_pkt;

typedef struct MyAVPacketList {
	AVPacket pkt;
	struct MyAVPacketList *next;
	int serial;
} MyAVPacketList;

typedef struct PacketQueue {
	MyAVPacketList *first_pkt, *last_pkt;
	int nb_packets;
	int size;
	int64_t duration;
	int abort_request;
	int serial;
	SDL_mutex *mutex;
	SDL_cond *cond;
} PacketQueue;


int packet_queue_init(PacketQueue *q);
void packet_queue_flush(PacketQueue *q);
void packet_queue_destroy(PacketQueue *q);
void packet_queue_abort(PacketQueue *q);
void packet_queue_start(PacketQueue *q);

int packet_queue_put_private(PacketQueue *q, AVPacket *pkt);
int packet_queue_put(PacketQueue *q, AVPacket *pkt);
int packet_queue_put_nullpacket(PacketQueue *q, int stream_index);
int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *serial);
#endif /* PacketQueue_h */
